//
// Created by lucy on 1/18/2024.
//

#ifndef OOP_MUTABLE_CONTAINER_MUTABLELINKEDCONTAINER_H
#define OOP_MUTABLE_CONTAINER_MUTABLELINKEDCONTAINER_H

#include "MutableContainer.h"
#include "LinkedNode.cpp"

template <typename E>
class MutableLinkedContainer : public MutableContainer<E>
{
private:
    LinkedNode<E> *first;
    LinkedNode<E> *last;
    int len;

    LinkedNode<E> *getNodeAtIndex(int index);
    LinkedNode<E> *merge(LinkedNode<E> *left, LinkedNode<E> *right);
    LinkedNode<E> *mergeSort(LinkedNode<E> *head);

public:
    MutableLinkedContainer();

    void printError();

    bool validIndex(int index) override;

    void add(E ele) override;

    void add(int index, E ele) override;

    E remove(int index) override;

    bool removeElement(E ele) override;

    void clear() override;

    E set(int index, E ele) override;

    E get(int index) override;

    void sort() override;

    int index(E ele) override;

    std::string str() override;

    int length() override;

    ~MutableLinkedContainer() override;
};

#endif // OOP_MUTABLE_CONTAINER_MUTABLELINKEDCONTAINER_H
